package com.ymttest.business.service;

import java.io.IOException;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.codec.binary.Base64;
import org.apache.http.client.ClientProtocolException;

import com.google.gson.JsonArray;
import com.shop2cn.iapi.shenqisettlement.parameter.resp.GetUserBandingBankCardInfoResp;
import com.shop2cn.iapi.shenqisettlement.service.GetUserBandingBankCardInfoCall;
import com.ymatou.common.lang.CipherUtil;
import com.ymatou.iapi.dglogin.parameter.AccessSourceEnum;
import com.ymatou.iapi.dglogin.parameter.AppSourceEnum;
import com.ymatou.iapi.dglogin.parameter.BuyerSendVerifyCodeBean;
import com.ymatou.iapi.dglogin.parameter.SellerRegisterBean;
import com.ymatou.iapi.dglogin.parameter.UserWxInfo;
import com.ymatou.iapi.dglogin.parameter.WxLoginBean;
import com.ymatou.iapi.dglogin.parameter.WxLoginSession;
import com.ymatou.iapi.dglogin.service.BuyerSendVerifyCodeCall;
import com.ymatou.iapi.dglogin.service.SellerRegisterCall;
import com.ymatou.iapi.dglogin.service.WxLoginCall;
import com.ymatou.iapi.dguser.parameter.*;
import com.ymatou.iapi.dguser.service.*;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymttest.database.model.ValidationCode;
import com.ymttest.database.mongo.UserTokenWapper;
import com.ymttest.database.sqlwapper.YmtValidationCodeWapperV2;
import com.ymttest.utils.AESUtil;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;

public class DGUserCallService {
	//wxAppConfig=wxsqBuyer|wxef012229113b2d43|1e75293e9acea7fa223181d8027181a3|0,wxsqSeller|wxef012229113b2d43|1e75293e9acea7fa223181d8027181a3|0
	public final static String TestWxsqBuyer="wxsqBuyer";
	public final static String TestWxsqSeller="wxsqSeller";
	public final static String TestWxsqOther="wxsqOther";
	public final static Integer TestWxsqOtherSellerId=500001106;
	public final static String TestWxAppName="wxsqSeller_501114357";
	public final static String DefImg="http://pic1.ymatou.com/G01/M00/3F/FD/rBBlD1yUmUqAXuUmAAAImzrFPOU662_1_1_o.png";
	public final static String SellerDefImg="http://pic1.ymatou.com/G01/M00/3F/CD/rBBlD1yTdyCAe7ruAABImnwn1Sc744_1_1_o.png";
	/**
	 * 用来修改的默认地址
	 */
	public final static String DefImg2="http://static.shop2cn.com/content/images/weixin2d-new.png";
	/**
	 * 	DG_BuyerWxApp 60 代购神器买家端小程序
	 */
	public final static Integer DG_BuyerWxApp=60;
	/**
	 * DG_SellerWxApp 62 代购神器商家端小程序
	 */
	public final static Integer DG_SellerWxApp=62;
	/**
	 * DG_SellerApp 63 代购神器商家端App
	 */
	public final static Integer DG_SellerApp=63;
	public final static String SESSIONKEY="0000000012345678";
	public final static String CDKEY="ymt_dg$$$";
	public final static String  IV="1234567800000000";
	
	
	/**
	 * 转换type 0->60  1->61 4->65 5->66
	 * @param AccessSource
	 * @return
	 */
	public static Integer getAppSourceCode(Integer AccessSource) {
		AppSourceEnum appSourceEnum;
        if (AccessSource== AccessSourceEnum.WXAPP.getCode()) {
            appSourceEnum = AppSourceEnum.GodUserWxApp;
        } else if (AccessSource== AccessSourceEnum.WXH5.getCode()){
            appSourceEnum = AppSourceEnum.GodUserWxH5App;
        }else if (AccessSource == AccessSourceEnum.ALIPAY.getCode()){
            appSourceEnum = AppSourceEnum.GodUserAliPayApp;
        }else if(AccessSource == AccessSourceEnum.DY.getCode()){
            appSourceEnum = AppSourceEnum.GodUserDyApp;
        }else if (AccessSource == AccessSourceEnum.TouTiao.getCode()){
            appSourceEnum = AppSourceEnum.GodUserTouTiaoApp;
        }else {
            //默认60
            appSourceEnum = AppSourceEnum.GodUserWxApp;
        }
        return appSourceEnum.getCode();
	}
	/**
	 * 修改微信信息
	 * @param updateuserwxinfoBean
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void updateUserWxinfo(UpdateUserWxinfoBean updateuserwxinfoBean) throws ClientProtocolException, IOException {
//		updateuserwxinfoBean.setGender(2);
//		updateuserwxinfoBean.setLogoUrl("http://pc1.img.ymatou.com/G01/shangou/M00/2C/D0/rBBlD1gHOV6AY32AAAEN6UG5TOc701.jpg");
//		updateuserwxinfoBean.setUserId(user);
//		updateuserwxinfoBean.setNickname("nihao");
		UpdateUserWxinfoCall updateuserwxinfoCall=new UpdateUserWxinfoCall();
		updateuserwxinfoCall.setData(updateuserwxinfoBean);
		updateuserwxinfoCall.callService();
	}
	/**
	 * 发送短信验证码-会员系统用
	 * @param mobile
	 * @return 返回验证码
	 * @throws IOException 
	 * @throws ClientProtocolException 
	 */
	public static String BuyerSendVerifyCodeCall(String mobile) throws ClientProtocolException, IOException {
		BuyerSendVerifyCodeBean buyersendverifycodeBean=new BuyerSendVerifyCodeBean();
		BuyerSendVerifyCodeCall buyersendverifycodeCall=new BuyerSendVerifyCodeCall();
		buyersendverifycodeBean.setMobile(mobile);
		buyersendverifycodeCall.setData(buyersendverifycodeBean);
		buyersendverifycodeCall.callService();			
		Logger.verifyEquals("true", buyersendverifycodeCall.getString("success"), "验证success");
		ValidationCode vc = new YmtValidationCodeWapperV2().getValidateData(buyersendverifycodeBean.getMobile());
		return vc.getCode();
	}
	
	/**
	 * 发送短信验证码-会员系统用-带区号
	 * @param mobile
	 * @return 返回验证码
	 * @throws IOException 
	 * @throws ClientProtocolException 
	 */
	public static String BuyerSendVerifyCodeCall(String AreaCode,String mobile) throws ClientProtocolException, IOException {
		BuyerSendVerifyCodeBean buyersendverifycodeBean=new BuyerSendVerifyCodeBean();
		BuyerSendVerifyCodeCall buyersendverifycodeCall=new BuyerSendVerifyCodeCall();
		buyersendverifycodeBean.setMobileAreaCode(AreaCode);
		buyersendverifycodeBean.setMobile(mobile);
		buyersendverifycodeCall.setData(buyersendverifycodeBean);
		buyersendverifycodeCall.callService();			
		Logger.verifyEquals("true", buyersendverifycodeCall.getString("success"), "验证success");
		ValidationCode vc = new YmtValidationCodeWapperV2().getValidateData(AreaCode+buyersendverifycodeBean.getMobile());
		return vc.getCode();
	}
	
	/**decryptWxEncryptedData依赖
	 * @param base64String
	 * @return
	 */
	public static byte[] decodeBase64(final String base64String) {
        return new Base64().decode(base64String);
    }
	/**
	 * 使用sessionKey和vi解密encryptedData 微信授权联登EncryptedData字段UserWxInfo对象的json
	 * @param encryptedData
	 * @param iv
	 * @param sessionKey
	 * @return
	 * @throws Exception
	 */
	public static UserWxInfo decryptWxEncryptedData(String encryptedData, String iv, String sessionKey) throws Exception {
        String decryptedData;
        try {
            byte[] sessionKeyBytes = decodeBase64(sessionKey);
            byte[] ivBytes = decodeBase64(iv);
            byte[] encryptedDataBytes = decodeBase64(encryptedData);

            decryptedData = AESUtil.decrypt(sessionKeyBytes, ivBytes, encryptedDataBytes);
        } catch (Exception e) {
            throw new Exception("解密微信用户加密信息失败:"+e.getMessage());
        }
        return (UserWxInfo) FormatUtil.GSONToObject(decryptedData, UserWxInfo.class);
    }
	/**
	 * 使用sessionKey和vi加密encryptedData 微信授权联登EncryptedData字段UserWxInfo对象的json
	 * @param encryptedData UserWxInfo对象的json
	 * @param iv
	 * @param sessionKey
	 * @return
	 * @throws Exception
	 */
	public static String encryptWxEncryptedData(String encryptedData, String iv, String sessionKey) throws Exception {
		Logger.debug("UserWxInfo:"+encryptedData);
        String decryptedData;
        try {
            decryptedData = AESUtil.encrypt(encryptedData, sessionKey, iv);
        } catch (Exception e) {
        	e.printStackTrace();
            throw new Exception("encryptedData:"+encryptedData+":sessionKey:"+sessionKey+":iv:"+iv+"微信用户加密信息失败:"+e.getMessage());
        }
        return decryptedData;
    }
    /**
     * 用于SessionKey 和 vi 加base64
     * @param info
     * @return
     */
    public String encodeBase64(String info){
        return org.apache.commons.codec.binary.Base64.encodeBase64String(info.getBytes(StandardCharsets.UTF_8));
    }
    /**
     * 获取WxLoginSession 加密后信息 使用CDKEY 加密
     * @param wxLoginSession
     * @return
     * @throws Exception
     */
    public static String encryptWxLoginSession(WxLoginSession wxLoginSession) throws Exception{
    	Logger.debug("wxLoginSession:"+FormatUtil.beanToGSONString(wxLoginSession));
        return CipherUtil.encryptAES(CDKEY, FormatUtil.beanToGSONString(wxLoginSession));
    }
    
    /**
     * 解码WxLoginSession
     * @param encryptedLoginSession
     * @return
     * @throws Exception
     */
    public static WxLoginSession decryptWxLoginSession(String encryptedLoginSession) throws Exception{
        String decryptText=CipherUtil.decryptAES(CDKEY, encryptedLoginSession);
        return (WxLoginSession)FormatUtil.GSONToObject(decryptText, WxLoginSession.class);
    }
    /**
     * 注册一个默认的seller
     * @return
     * @throws Exception
     */
    public static SellerRegisterCall regDefSellerRegister() throws Exception {
    	UserCreateBean u= DGUserCallService.initUsercreateBean();
		u.setInvitationCode("test");
		u.setMobile(TestDataManager.getPhoneNum());
		u.setMobileAreaCode("86");
		u.setUserType(1);
		u.setAppSource(DGUserCallService.DG_SellerApp);
		u.setWxAppName(DGUserCallService.TestWxsqSeller);
		SellerRegisterBean sellerregisterBean=new SellerRegisterBean();
		SellerRegisterCall sellerregisterCall=new SellerRegisterCall();
		sellerregisterBean=initSellerRegBean(u);
		sellerregisterCall.setData(sellerregisterBean);
		sellerregisterCall.callService();
		return sellerregisterCall;
    }
    /**
     * 初始化SellerReg
     * @param u
     * @return
     * @throws Exception
     */
    public static SellerRegisterBean initSellerRegBean(UserCreateBean u) throws Exception {
		SellerRegisterBean srb=new SellerRegisterBean();
		srb.setAppSource(u.getAppSource());
		srb.setClientIp(u.getClientIp());
		srb.setCountryCode(u.getCountryCode());
		srb.setInvitationCode(u.getInvitationCode());
		srb.setLoginSession(getLoginSession(u));
		srb.setLogoUrl(u.getLogoUrl());
		srb.setMobile(u.getMobile());
		srb.setMobileAreaCode(u.getMobileAreaCode());
		srb.setNickname(u.getNickname());
		srb.setTerminalSource(u.getTerminalSource());
		srb.setUserGender(u.getUserGender());
		srb.setWxAppName(u.getWxAppName());
		return srb;
	}
    /**
     * 创建loginsession
     * @param u
     * @return
     * @throws Exception
     */
    public static String getLoginSession(UserCreateBean u) throws Exception {
		WxLoginSession wxLoginSession=new WxLoginSession();
		wxLoginSession.setOpenId(u.getOpenId());
		wxLoginSession.setSessionKey(TestDataManager.getUTF8Base64(DGUserCallService.SESSIONKEY));
		wxLoginSession.setUnionId(u.getUnionId());
		String loginSession = DGUserCallService.encryptWxLoginSession(wxLoginSession);
		return loginSession;
	}
	/**
	 * 初始化创建用户bean
	 * @return
	 */
	public static UserCreateBean initUsercreateBean() {
		UserCreateBean usercreateBean = new UserCreateBean();
		usercreateBean.setAppSource(DG_BuyerWxApp);
		usercreateBean.setChannelSource(6);
		usercreateBean.setClientIp(TestDataManager.getRandomIp());
		usercreateBean.setCountryCode("China");
		usercreateBean.setLogicDeviceId(TestDataManager.getRandomUUID().toString());
		usercreateBean.setPhysicsDeviceId(TestDataManager.getRandomUUID().toString());
		usercreateBean.setLoginId(TestDataManager.getRandomUUID().toString().replaceAll("-", ""));
		usercreateBean.setLoginPwd("testpwd");
		usercreateBean.setLogoUrl(DGUserCallService.DefImg2);
		usercreateBean.setNickname("NickautoTest");
		usercreateBean.setOpenId("oid" + TestDataManager.getRandomNum(6) + System.currentTimeMillis() % 1000);
		usercreateBean.setUnionId("uid" + TestDataManager.getRandomNum(6) + System.currentTimeMillis() % 1000);
		usercreateBean.setRemark("remarkAutoTest");
		usercreateBean.setTerminalSource(0);
		usercreateBean.setUserGender(1);
		usercreateBean.setUserType(0);
		usercreateBean.setWxAppName(TestWxsqBuyer);
		return usercreateBean;
	}
	/**
	 * 初始化创建用户bean-商家
	 * @return
	 */
	public static UserCreateBean initSellerUsercreateBean() {
		UserCreateBean usercreateBean = new UserCreateBean();
		usercreateBean.setChannelSource(6);
		usercreateBean.setClientIp(TestDataManager.getRandomIp());
		usercreateBean.setCountryCode("China");
		usercreateBean.setLogicDeviceId(TestDataManager.getRandomUUID().toString());
		usercreateBean.setPhysicsDeviceId(TestDataManager.getRandomUUID().toString());
		usercreateBean.setLoginId("LID" + TestDataManager.getRandomNum(6) + System.currentTimeMillis() % 1000);
		usercreateBean.setLoginPwd("testpwd");
		usercreateBean.setLogoUrl(DGUserCallService.DefImg2);
		usercreateBean.setNickname("NickautoTest");
		usercreateBean.setOpenId("oid" + TestDataManager.getRandomNum(6) + System.currentTimeMillis() % 1000);
		usercreateBean.setUnionId("uid" + TestDataManager.getRandomNum(6) + System.currentTimeMillis() % 1000);
		usercreateBean.setRemark("remarkAutoTest");
		usercreateBean.setTerminalSource(0);
		usercreateBean.setUserGender(1);
		usercreateBean.setIscs(false);
		usercreateBean.setMobile(TestDataManager.getPhoneNum());
		usercreateBean.setMobileAreaCode("86");
		usercreateBean.setUserType(1);
		usercreateBean.setAppSource(DGUserCallService.DG_SellerWxApp);
		usercreateBean.setWxAppName(DGUserCallService.TestWxsqSeller);
		return usercreateBean;
	}
	public static UserCreateBean initCsUsercreateBean() {
		UserCreateBean usercreateBean = new UserCreateBean();
		usercreateBean.setChannelSource(6);
		usercreateBean.setClientIp(TestDataManager.getRandomIp());
		usercreateBean.setCountryCode("China");
		usercreateBean.setLogicDeviceId(TestDataManager.getRandomUUID().toString());
		usercreateBean.setPhysicsDeviceId(TestDataManager.getRandomUUID().toString());
		usercreateBean.setLoginId("LID" + TestDataManager.getRandomNum(6) + System.currentTimeMillis() % 1000);
		usercreateBean.setLoginPwd("testpwd");
		usercreateBean.setLogoUrl(DGUserCallService.DefImg2);
		usercreateBean.setNickname("NickautoTest");
		usercreateBean.setOpenId("oid" + TestDataManager.getRandomNum(6) + System.currentTimeMillis() % 1000);
		usercreateBean.setUnionId("uid" + TestDataManager.getRandomNum(6) + System.currentTimeMillis() % 1000);
		usercreateBean.setRemark("remarkAutoTest");
		usercreateBean.setTerminalSource(0);
		usercreateBean.setUserGender(1);
		usercreateBean.setIscs(true);
		usercreateBean.setUserType(1);
		usercreateBean.setAppSource(DGUserCallService.DG_SellerWxApp);
		usercreateBean.setWxAppName(DGUserCallService.TestWxsqSeller);
		return usercreateBean;
	}
	/**
	 * 创建用户
	 * @param usercreateBean
	 * @return
	 * @throws Throwable
	 */
	public static Integer UserCreateCall(UserCreateBean usercreateBean) throws Exception {
		UserCreateCall usercreateCall=new UserCreateCall();
		usercreateCall.setData(false,usercreateBean);
		usercreateCall.callService();
		return Integer.valueOf(usercreateCall.getString("userId"));
	}
	
	/**
	 * 初始化一个用户绑定信息
	 * @param usercreateBean
	 * @return
	 * @throws Throwable
	 */
	public static void UserBind(int user,String unionid) throws Exception {
		UserBind(user, unionid, DGUserCallService.TestWxsqBuyer);
	}
	/**
	 * 初始化一个用户绑定信息
	 * @param usercreateBean
	 * @return
	 * @throws Throwable
	 */
	public static void UserBind(int user,String unionid,String appname) throws Exception {
		BindBean bindBean = new BindBean();
		BindCall bindCall = new BindCall();
		UserDto dgUserInfo = DGUserCallService.getDGUserInfo(user);
		bindBean.setUserId(user);
		bindBean.setAppSource(62);
		bindBean.setOpenId("oid" + TestDataManager.getRandomNum(5) + System.currentTimeMillis() % 1000);
		bindBean.setUnionId(unionid);
		bindBean.setWxAppName(appname);
		bindCall.setData(bindBean);
		bindCall.callService();
//		Logger.verifyEquals("true", bindCall.getString("success"), "验证success");
	}
	/**
	 * 根据手机号和区号获取商家id
	 * @param mobile
	 * @param mobileAreaCode
	 * @return sellerid
	 * @throws Exception
	 */
	public static Integer getSellerIdByMoblie(String mobile,String mobileAreaCode)  throws Exception{
		try{
		GetSellerInfoByMobileBean getsellerinfobymobileBean=new GetSellerInfoByMobileBean();
		GetSellerInfoByMobileCall getsellerinfobymobileCall=new GetSellerInfoByMobileCall();
		getsellerinfobymobileBean.setMobile(mobile);
		getsellerinfobymobileBean.setMobileAreaCode(mobileAreaCode);
		getsellerinfobymobileCall.setData(getsellerinfobymobileBean);
		getsellerinfobymobileCall.callService();			
		return getsellerinfobymobileCall.getJsonObject().get("sellerDto").getAsJsonObject().get("userId").getAsInt();
		}catch(Exception e)
		{
			return 0;
		}
		
	}
	/**
	 * 获取用户信息
	 * @param userid
	 * @return
	 * @throws Exception
	 */
	public static UserDto getDGUserInfo(Integer userid)  throws Exception{
		GetuserBean getuserBean=new GetuserBean();
		GetuserCall getuserCall=new GetuserCall();
		getuserBean.setUserId(userid);
		getuserCall.setData(getuserBean);
		getuserCall.callService();
		return getuserCall.getUserDto();
		
	}
	
	public static boolean GetUserByUsernameAndPwd(String username,String password) throws ClientProtocolException, IOException{
		GetUserByUsernameAndPwdBean b=new GetUserByUsernameAndPwdBean();
		GetUserByUsernameAndPwdCall c=new GetUserByUsernameAndPwdCall();
		
		b.setUsername(username);
		b.setPassword(password);
		c.setData(b);
		c.callService();			
		Logger.verifyEquals("true", c.getString("success"), "验证success");
		return c.getJsonObject().get("userDto")==null?false:true;
	}
	
	/**
	 * 获取用户绑定信息
	 * @param userid
	 * @return 
	 * @return
	 * @throws Exception
	 */
	public static JsonArray getDGUserBindInfo(Integer userid)  throws Exception{
		GetUserBindInfoBean getUserBindInfoBean = new GetUserBindInfoBean();
		GetUserBindInfoCall getUserBandInfoCall = new GetUserBindInfoCall();
		getUserBindInfoBean.setUserId(userid);
		getUserBandInfoCall.setData(getUserBindInfoBean);
		getUserBandInfoCall.callService();
		
//		UserBindDto
		Logger.verifyEquals("true", getUserBandInfoCall.getString("success"), "验证success");
		return getUserBandInfoCall.getJsonObject().get("userBindDtos").getAsJsonArray();
	}
	/**
	 * 删除用户
	 * @param userid
	 * @return
	 * @throws Exception
	 */
	public static Boolean DeleteUser(Integer userid)  throws Exception{
		DeleteBean deleteBean=new DeleteBean();
		DeleteCall deleteCall=new DeleteCall();
		deleteBean.setUserId(userid);
		deleteCall.setData(deleteBean);
		deleteCall.callService();			
		return deleteCall.getJsonObject().get("success").getAsBoolean();
	}
	
	/**
	 * 修改登录密码
	 * @param userid
	 * @return
	 * @throws Exception
	 */
	public static Boolean UpdatePwd(Integer userid,String pwd)  throws Exception{
		UpdatepwdBean updatepwdBean = new UpdatepwdBean();
		UpdatepwdCall updatepwdCall = new UpdatepwdCall();
		updatepwdBean.setUserId(userid);
		updatepwdBean.setPwd(pwd);
		updatepwdCall.setData(updatepwdBean);
		updatepwdCall.callService();			
		Logger.verifyEquals("true", updatepwdCall.getString("success"), "验证code");
		return updatepwdCall.getJsonObject().get("success").getAsBoolean();
	}
	
	/**
	 * 初始化创建用户bean
	 * @return
	 */
	public static CreateUserBackBean initUsercreateNewBean() {
		CreateUserBackBean usercreateBean = new CreateUserBackBean();
		usercreateBean.setMobile(TestDataManager.getPhoneNum());
		usercreateBean.setMobileAreaCode("86");
		usercreateBean.setLoginPwd("ceshi1234");
		usercreateBean.setUserType(0);
		usercreateBean.setCountryCode("China");
		usercreateBean.setChannelSource(6);
		usercreateBean.setTerminalSource(3);
		usercreateBean.setAppSource(DG_SellerWxApp);
		usercreateBean.setWxAppId("wxAppId");
		usercreateBean.setSecret("wxSecret");
		return usercreateBean;
	}
	
	/**
	 * 创建用户
	 * @param usercreateBean
	 * @return
	 * @throws Throwable
	 */
	public static Integer UserCreateNewCall(CreateUserBackBean usercreateBean) throws Exception {
		CreateUserBackCall usercreateCall=new CreateUserBackCall();
		usercreateCall.setData(false,usercreateBean);
		usercreateCall.callService();
		return Integer.valueOf(usercreateCall.getString("userId"));
	}
	
	public static int GetByMobileAndPwd(String mobile,String password) throws ClientProtocolException, IOException{
		GetByMobileAndPwdBean b=new GetByMobileAndPwdBean();
		GetByMobileAndPwdCall c=new GetByMobileAndPwdCall();
		b.setMobile(mobile);
		b.setPassword(password);
		c.setData(b);
		c.callService();			
		Logger.verifyEquals("true", c.getString("success"), "验证success");
		return c.getJsonObject().get("userDto").getAsJsonObject().get("userId").getAsInt();
	}
	
	/**
	 * 初始化创建用户回调
	 * @return
	 * @throws IOException 
	 * @throws ClientProtocolException 
	 */
	public static void ReceiveUserCreateNewCall(int user) throws ClientProtocolException, IOException {
		ReceiveCreateBackUserBean receivecreatebackuserBean = new ReceiveCreateBackUserBean();
		ReceiveCreateBackUserCall receivecreatebackuserCall = new ReceiveCreateBackUserCall();
		
		receivecreatebackuserBean.setHpAccount("hpAccount");
		receivecreatebackuserBean.setMchId(user);
		receivecreatebackuserBean.setWxAppId("wxAppId");
		receivecreatebackuserBean.setWxAppIdApp("wxAppIdApp");
		receivecreatebackuserBean.setWxAppIdBuyer("wxAppIdBuyer");
		receivecreatebackuserBean.setWxAppIdH5("wxAppIdH5");
		receivecreatebackuserBean.setWxAppIdPc("wxAppIdPc");
		receivecreatebackuserBean.setWxSecret("wxSecret");
		receivecreatebackuserBean.setWxSecretApp("wxSecretApp");
		receivecreatebackuserBean.setWxSecretBuyer("wxSecretBuyer");
		receivecreatebackuserBean.setWxSecretH5("wxSecretH5");
		receivecreatebackuserBean.setWxSecretPc("wxSecretPc");

		receivecreatebackuserCall.setData(receivecreatebackuserBean);
		receivecreatebackuserCall.callService();
		Logger.verifyEquals("ok",receivecreatebackuserCall.getReturnData(), "验证回调是否成功");
	
	}
	
	
	/**
	 * 微信解绑
	 * @param userid
	 * @return
	 * @throws Exception
	 */
	public static void unWxBind(int userId)  throws Exception{
		UnwxbindBean unwxbindBean = new UnwxbindBean();
		UnwxbindCall unwxbindCall = new UnwxbindCall();
		unwxbindBean.setUserId(userId);
		unwxbindCall.setData(unwxbindBean);
		unwxbindCall.callService();
		Logger.verifyEquals("true", unwxbindCall.getString("success"), "验证code");
	}
	
	/**
	 * 微信登录
	 * @param userid
	 * @return 
	 * @return
	 * @throws Exception
	 */
	public static Map<String, Object> WxLogin(UserCreateBean u,int userid)  throws Exception{
		WxLoginBean wxloginBean=new WxLoginBean();
		WxLoginCall wxloginCall = new WxLoginCall();
		wxloginBean.setWxAppName(DGUserCallService.TestWxsqBuyer);
		wxloginBean.setAppSource(u.getAppSource());
		wxloginBean.setClientIp(TestDataManager.getRandomIp());
		wxloginBean.setJsCode("autotestjscode");
		wxloginBean.setTerminalSource(u.getTerminalSource());
		wxloginBean.setUserType(u.getUserType());
		wxloginCall.addHeader("mock", "mock-enable");
		wxloginCall.addHeader("mockId-1", TestDataManager.getRandomUUID().toString());
		wxloginCall.addHeader("mockApi-1", "dgLoginWxClient-getLoginSession-Normal");
		wxloginCall.addHeader("mockParam-1-sessionKey",DGUserCallService.SESSIONKEY);
		wxloginCall.addHeader("mockParam-1-openId",u.getOpenId());
		wxloginCall.addHeader("mockParam-1-unionId",u.getUnionId());
		wxloginCall.setData(wxloginBean);
		wxloginCall.callService();			
//		Logger.verifyEquals("true", wxloginCall.getString("success"), "验证success");
//		//已有uid 不需要返回uid false
//		Logger.verifyEquals("false",wxloginCall.getString("needUpdateUnionId"), "验证needUpdateUnionId");
		try {
			Map<String, Object> token = new UserTokenWapper().getUserTokenByUid(Integer.valueOf(wxloginCall.getString("userId")));
			return token;
		} catch (Exception e) {
			return null;
		}
//		Logger.comment(token.toString());
//		Logger.verifyEquals(AppSourceEnum.parse(u.getAppSource()).toString().toLowerCase(), token.get("tSource"), "验证tSource");
//		Logger.verifyEquals("true", wxloginCall.getString("success"), "验证success");
		
	}
	
	
	public static void main(String[] args) throws Throwable {
//		UserCreateBean u = DGUserCallService.initUsercreateBean();
		StringBuffer sb = new StringBuffer();
		StringBuilder sb2 = new StringBuilder();
		long t1 = System.currentTimeMillis();
		for (int i = 0; i < 100000; i++) {
			sb.append("a");
		}
		long t2 = System.currentTimeMillis();
		Logger.debug(t2-t1);
		long t3 = System.currentTimeMillis();
		for (int i = 0; i < 100000; i++) {
			sb2.append("a");
		}
		long t4 = System.currentTimeMillis();
		Logger.debug(t4-t3);
	}
}
